package com.dyh.quickdemo.demos.lbdand;

/*
@Author=Joey Wheeler
@Date=2020/12/4 17:12
*/
public class CircuitBreaker {

    Runnable r;
    String resourceName;

    private CircuitBreaker(String resourceName,Runnable r){
        this.r = r;
        this.resourceName = resourceName;
    }

    public static CircuitBreaker node(String resourceName,Runnable r){
        CircuitBreaker breaker = CircuitBreakerCenter.find(resourceName);
        if (breaker !=null)
            return breaker;
        breaker = new  CircuitBreaker(resourceName,r);
        CircuitBreakerCenter.regist(breaker);
        return breaker;
    }

    public  void work(){
        this.r.run();
    }
}
